package com.cloud.alibaba.rest.service;

import com.cloud.alibaba.common.util.EmailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * @program: cloud-alibaba
 * @description: 邮件服务
 * @author: taoxinhuan
 * @create: 2021-03-24 11:09
 **/
@Service
@Slf4j
public class EmailService {


    /**
     * @author taoxinhuan
     * @description: 发送邮件服务
     * @date 2020/8/31 14:47
     */


    @Value("${app.email.smtp_url}")
    private String defaultSmtp;

    @Value("${app.email.account}")
    private String defaultAccount;

    @Value("${app.email.identity}")
    private String defaultIdentity;

    //个性化短信发送
    public void sendEmail(String smtp, String form, String formIdentity, String to, String title, String content) {
        EmailUtil.sendEmail(smtp, form, formIdentity, to, title, content);
    }

    //使用系统默认配置的账户发送短信
    public void sendEmail(String to, String title, String content) {
        sendEmail(defaultSmtp, defaultAccount, defaultIdentity, to, title, content);
    }

    public void sendNewsToOther() {
        String one = EmailUtil.getOneS();
        this.sendEmail("369548984@qq.com", "亲爱的会员:", one);
    }

    @Scheduled(cron = "0 0 0/1 * * ?")
    @PostConstruct
    public void generateCoreIndexReport() {
        log.info("000000000000000");
        this.sendNewsToOther();
    }
}

